home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / ttga10.zip / TTGA.C < prev    next >
C/C++ Source or Header  |  1992-05-20  |  4KB  |  161 lines

  1. /*
  2.    TTGA.c
  3.  ------------------------------------------------------------------------------
  4.                     HCTARGA.H, HCTGAV.C, HCSVGAS.LIB are
  5.                Copyright 1990,1991 of Synergrafix Consulting
  6.                           All Rights Reserved.
  7.  ------------------------------------------------------------------------------
  8.  *                                                                            *
  9.  * TTGA.EXE - TsengTGA                       18/05/92    by Luigino Masarati  *
  10.  *                                                                            *
  11.  * v1.0                                                                       *
  12.  *                                                                            *
  13.  ------------------------------------------------------------------------------
  14. */
  15.  
  16. #include <stdio.h>
  17. #include <string.h>
  18. #include "hctarga.h"
  19. #include "dosutil.h"
  20.  
  21. #define   VERSION           "1.0"
  22.  
  23. char errmsg[256];
  24. int i;
  25.  
  26. void header()  {
  27.     printf("\nTsengTGA v%s\n",VERSION);
  28.     printf("(c)1992 by Luigino Masarati.\n");
  29.     printf("Targa 32/24/16 File Utility for Tseng ET4000 HiColor.\n\n");
  30.     }
  31.  
  32. void usage()  {
  33.         printf("Usage: TTGA <options> filename[.TGA] [output16file[.TGA]]\n");
  34.         printf("<options>:\n");
  35.         printf("-d = Dithering on                   -h = Help\n");
  36.         printf("-c = Save Compressed Targa16 File   -? = Help\n");
  37.         }
  38.  
  39. void error(char *s) {
  40.     fcloseall();
  41.     hctextmode();
  42.     header();
  43.     printf("%s\n",s);
  44.     exit(1);
  45.     }
  46.                                 /* Routine to analize parameters */
  47.  
  48. int main(int argc,char *argv[]) {
  49.  
  50.     int err,mode,w,h,commentsize;
  51.     unsigned char comment[256];
  52.  
  53.     switch (analyzeParams (argc, argv, "DCH?")) {
  54.  
  55.         case parMissing: {
  56.                         header();
  57.                         printf("Missing Parameter!\n\n");
  58.                         usage();
  59.                         exit(1);
  60.         }
  61.  
  62.         case parUnknown: {
  63.             header();
  64.             printf("Unknown Parameter!\n\n");
  65.             usage();
  66.             exit(1);
  67.         }
  68.     }
  69.  
  70.         if (flag('H')||flag('?')) {
  71.         header();
  72.         usage();
  73.                 exit(1);
  74.                 }
  75.  
  76.                         /* Checks if inputfile exists */
  77.  
  78.         if (path (0) != NULL) {
  79.                 changeExt (path (0), ".TGA");
  80.                 if (access(path(0),0)!=0) {
  81.                     header();
  82.                     printf("Cannot find %s !\n",path(0));
  83.                     exit(1);
  84.                 }
  85.  
  86.                         /* Get size of TGA file */
  87.  
  88.     err=hctgasize(path(0),&w,&h,&commentsize,&comment);
  89.     switch (err) {
  90.         case HCTGACANTOPEN:
  91.             error("Can't open input file!");
  92.             break;
  93.         case HCTGANOMEM:
  94.             error("Not enough memory to load file!");
  95.         case HCTGANOTSUPPORTED:
  96.             error("File type not supported!");
  97.         case HCTGACANTREAD:
  98.             error("Error reading file!");
  99.         }
  100.  
  101.                         /* Set Hicolor mode */
  102.  
  103.     mode=hcmodesize(w,h);
  104.     if (mode<2) mode=2;
  105.     if (mode>3) mode=3;
  106.     if (!hcsetmodetseng(mode))
  107.         error("No HiColor DAC, not Tseng Chipset, or can't set mode!");
  108.  
  109.  
  110.                         /* View TGA file */
  111.  
  112.     err=hctgaview(path(0),-1,-1,-1,-1,(flag ('D')));
  113.     switch (err) {
  114.         case HCTGACANTOPEN:
  115.             error("Can't open input file!");
  116.             break;
  117.         case HCTGANOMEM:
  118.             error("Not enough memory to load file!");
  119.         case HCTGANOTSUPPORTED:
  120.             error("File type not supported!");
  121.         case HCTGACANTREAD:
  122.             error("Error reading file!");
  123.         }
  124.     }
  125.     else {
  126.         header();
  127.         printf("Filename missing!\n\n");
  128.         exit(1);
  129.         }
  130.  
  131.                                                 /* Save TGA 16 Compressed File */
  132.  
  133.     if (path (1) != NULL) {
  134.         changeExt (path (1), ".TGA");
  135.         err=hctgasave(path(1),-1,-1,-1,-1,(flag ('C')),commentsize,&comment);
  136.         switch (err) {
  137.             case HCTGACANTOPEN:
  138.                 error("Can't open output file!");
  139.                 break;
  140.             case HCTGANOMEM:
  141.                 error("Not enough memory to save file!");
  142.             case HCTGACANTWRITE:
  143.                 error("Error writing output file!");
  144.             }
  145.         }
  146.  
  147.         sound(300);
  148.         delay(20);
  149.     nosound();
  150.  
  151.     getch();                               /* Exit */
  152.  
  153.     hctextmode();
  154.     header();
  155.         printf("This program is 'GratisWare', distribute it all around the world !\n");
  156.  
  157.     return 0;
  158.     }
  159.  
  160.  
  161.